<?php
/**
+----------------------------------------------------------
* 
	涉及SESSION：　openid  
+----------------------------------------------------------
*/
class MonitorAction extends CommonAction
{
	private $appid;
	private $appsecret;
	
	Public function _initialize(){
		
		
		
	}
	
	Public function getAllData(){
	
		$code_yx = array(
			'16' => '数控系',
			'17' => '机械系',
			'18' => '汽车系',
			'19' => '电气系',
			'20' => '信息系',
			'21' => '文旅系',
			'110' => '其他'
		);
		
		
		$retData = array();
		
		// 内外宿
		$neiwai = array();
		$sql = "
			SELECT 
				sum( rzrs )  as nan,
				sum( rzrs_wman )  as nv
			FROM mt_rm_static_banji
		";
		$res = M()->query($sql);
		$neiwai['nei'] = $res[0];
		$sql = "
			SELECT 
				sum( wrzrs )  as nan,
				sum( wrzrs_wman )  as nv
			FROM mt_rm_static_banji
		";
		$res = M()->query($sql);
		$neiwai['wai'] = $res[0];
		$retData['neiwai']  = $neiwai; //--
		
		// 总男、女生
		$nannv = array();
		$nannv['nan'] = $retData['neiwai']['nei']['nan'] + $retData['neiwai']['wai']['nan'] ; //总男生＝内宿男生+外宿男生
		$nannv['nv'] = $retData['neiwai']['nei']['nv'] + $retData['neiwai']['wai']['nv'] ; //总女生同上
		$retData['znannv'] = $nannv;
		
		// 总人数    -- 
		$retData['zrenshu'] = $nannv['nan'] + $nannv['nv'];
		
		// 男女床位已住、空闲统计   -- 
		$nannv_cw = array();
		$sql = "
			SELECT 
				sum(kxcws) as kxcws,
				sum(yxcws) as yxcws,
				sum(cws)   as cws
			FROM mt_rm_static_lou 
			WHERE DY_MC LIKE '%女%'
		";
		$res = M()->query($sql);
		$nannv_cw['nv'] = $res[0]; //女生
		$sql = "
			SELECT 
				sum(kxcws) as kxcws,
				sum(yxcws) as yxcws,
				sum(cws)   as cws
			FROM mt_rm_static_lou 
			WHERE DY_MC                 NOT LIKE    '%女%'
		";
		$res = M()->query($sql);
		$nannv_cw['nan'] = $res[0]; //男生
		$retData['nannv_cw'] = $nannv_cw;
		
		// 楼栋床位统计
		$loudong_cw = array();
		$sql  = "
			SELECT *
			FROM mt_rm_static_lou
			ORDER BY DY_DM DESC
		";
		$loudong_cw = M()->query($sql);
		$retData['loudong_cw'] = $loudong_cw;
		
		//院系人数
		$yx_rs = array();
		$sql = "
			SELECT *
			FROM mt_yx_rs
			ORDER BY YX_ID ASC
		";
		$res = M()->query($sql);
		$retData['yx_rs'] = $res;
		
		
		// 专业分类人数－－－－－
		//C类
		$zyflrs = array();
		$sql = "SELECT    'C' as type ,  SUM(count) as sum  FROM mt_zy_rs  
				  WHERE  ZWMC like '%c%'    ";
		$res= M()->query($sql);
		array_push($zyflrs,$res[0]);
		//Z类
		$sql = "SELECT    'Z' as type ,  SUM(count) as sum  FROM mt_zy_rs  
				  WHERE  ZWMC like '%Z%'    ";
		$res= M()->query($sql);
		array_push($zyflrs,$res[0]);
		//J类
		$sql = "SELECT    'J' as type ,  SUM(count) as sum  FROM mt_zy_rs  
				  WHERE  ZWMC like '%J%'   ";
		$res= M()->query($sql);
		array_push($zyflrs,$res[0]);
		//GW类
		$sql = "SELECT    'GW' as type ,  SUM(count) as sum  FROM mt_zy_rs  
				  WHERE  ZWMC like '%GW%'   ";
		$res= M()->query($sql);
		array_push($zyflrs,$res[0]);
		//GS类
		$sql = "SELECT    'GS' as type ,  SUM(count) as sum  FROM mt_zy_rs  
				  WHERE  ZWMC like '%GS%'   ";
		$res= M()->query($sql);
		array_push($zyflrs,$res[0]);
		//G类
		$sql = "SELECT    'G' as type ,  SUM(count) as sum  FROM mt_zy_rs  
				  WHERE  ZWMC like '%G%'  
				     AND ZWMC NOT like '%GS%'
					 AND ZWMC NOT like '%GW%'
					 ";
					 
		$res= M()->query($sql);
		array_push($zyflrs,$res[0]);
		
		//dump($zyflrs);
		$retData['zyfl_rs'] = $zyflrs;
		
		
		
		// 专业人数 
		$zy_rs = array();
		$sql = "
			SELECT *
			FROM mt_zy_rs 
			ORDER BY ZGBM ASC,ZYDM ASC
		";
		$zy_rs = M()->query($sql);
		foreach($zy_rs as $key => $val){
			if( !in_array( $val['ZGBM'],array('16','17','18','19','20','21'))  ){
				$zy_rs[$key]['my_zgbm_mc'] = $val['ZGBM'];
			}else{
				$zy_rs[$key]['my_zgbm_mc'] = $code_yx[$val['ZGBM']];
			}
		}
		$retData['zy_rs'] = $zy_rs;
		
		
		// 班级人数 
		$bj_rs = array();
		$sql = "
			SELECT *
			FROM mt_bj_rs 
			ORDER BY YX_ID ASC,SSBJ_ID ASC
		";
		$bj_rs = M()->query($sql);
		foreach($bj_rs as $key => $val){
			if( !in_array( $val['YX_ID'],array('16','17','18','19','20','21'))  ){
				$bj_rs[$key]['my_zgbm_mc'] = $val['YX_ID'];
			}else{
				$bj_rs[$key]['my_zgbm_mc'] = $code_yx[$val['YX_ID']];
			}
		}
		$retData['bj_rs'] = $bj_rs;
		
		
	
		//dump($retData);
		
		echo $_REQUEST['callback'];
		echo '(';
		echo json_encode($retData);
		echo ')';
		
		
		
		
	}

	Public function getZongSeries(){
	
		$code_yx = array(
			'16' => '数控系',
			'17' => '机械系',
			'18' => '汽车系',
			'19' => '电气系',
			'20' => '信息系',
			'21' => '文旅系',
			'110' => '其他'
		);
		
		
		$retData = array();
		
		// 总人数曲线
		$count = array();
		$sql = "
			SELECT 
			  count_xs,
			  DATE_FORMAT(time,'%d日%H:%i') as time,
			  time as time2
			FROM mt_base_count
			ORDER BY time2 asc
		";
		$res = M()->query($sql);
		foreach($res as $key => $val){
			unset($res[$key]['time2']);
		}
		$retData['count']  = $res; //--
		
		//dump($retData);
		
		echo $_REQUEST['callback'];
		echo '(';
		echo json_encode($retData);
		echo ')';
		
		
		
		
	}

}
?>